<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="./plugin/layui/css/layui.css"/>
    <script src="plugin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <style>
        #videoList {
            width: 400px;
            height: 250px;
            border-style: solid;
            border-color: #00a65a;
            margin-left: 300px;
            float: left;
        }

        #videoBtn {
            margin-left: 500px;
        }

        #chooseBtn {
            margin-top: 217px;
            float: left;
        }

        body {
            background-color: rgba(192, 192, 192, 0.3);
        }
    </style>
</head>
<body>
<div id="videoList">

</div>
<div id="chooseBtn">
    <button type="button" class="layui-btn" id="choose">
        选择视频
    </button>
</div>
<div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">知识点</label>
            <div class="layui-input-block">
                <input type="text" name="knowledge" id="knowledge" required lay-verify="required" placeholder="请输入内容"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">公开等级</label>
            <div class="layui-input-block">
                <select name="open" id="open" lay-verify="required">
                    <option value="0">全市</option>
                    <option value="1">全校</option>
                    <option value="2">本班</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="content" id="content" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
    </form>
</div>

<div id="videoBtn">
    <button type="button" class="layui-btn" id="video">
        <i class="layui-icon">&#xe67c;</i>上传视频
    </button>
</div>

    <script>
        /*李英勇：视频上传*/



        let refreshToken = localStorage.getItem("refreshToken");
        let token = localStorage.getItem("token");

    layui.use(['jquery', 'layer', 'upload', 'form'], function () {
        let $ = layui.jquery, layer = layui.layer, upload = layui.upload, form = layui.form;
        //执行实例
        var uploadInst = upload.render({
            elem: '#choose' //绑定元素
            , url: 'upVideo' //上传接口
            , accept: 'video' //允许上传的文件类型
            , size: 30720 //最大允许上传的文件大小，单位kb
            , auto: false //关闭自动提交
            , bindAction: '#video'
            , headers: {refreshToken: refreshToken, token: token}
            , data: {
                "knowledge": function () {
                    return $("#knowledge").val()
                },
                "open": function () {
                    return $("#open").val()
                },
                "content": function () {
                    return $("#content").val()
                },
                "refreshToken": function () {
                    return refreshToken
                }
            }
            , before: function (obj) { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
            }
            , done: function (res) {
                //上传完毕回调
                layer.msg(res.msg);
                console.log(res.data);
                if (res.code == 0) {
                    $("#videoList").html("<video width='400' height='250' controls autoplay> <source src='/classteacher" + res.data + "' type='video/mp4'> </video>");

                }
            }
            , error: function () {
                //请求异常回调
            }
        });
    });
</script>
</body>
</html>